package com.jk.kdd.system.service;

import com.jk.kdd.system.dao.SystemRoleMapper;
import com.jk.kdd.system.model.SystemRole;
import com.jk.kdd.system.vo.SystemRoleVO;
import com.jk.util.BaseDataUtil;
import org.smart4j.framework.helper.BeanHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by DELL on 2016/10/9.
 */
@Service("systemRoleService")
public class SystemRoleServiceImpl implements  SystemRoleService{

    @Resource
    private SystemRoleMapper systemRoleMapper;

    /**
     * 获取实体列表
     */
    public List<SystemRoleVO> getSystemRoleList() {
        List<SystemRole> systemRole = systemRoleMapper.selectAll();
        List<SystemRoleVO> tagVOList = BeanHelper.mapList(systemRole,SystemRoleVO.class);
        return tagVOList;
    }
    /**
     * 根据主键获取实体
     */
    public SystemRoleVO getSystemRoleByPK(SystemRole user) {

        SystemRole systemRole = systemRoleMapper.selectByPrimaryKey(user.getId());
        SystemRoleVO systemRoleVO = new SystemRoleVO();
        BeanHelper.copyBean(systemRole,systemRoleVO);
        return systemRoleVO;
    }

    /**
     * 创建实体
     */
    @Transactional
    public boolean createSystemRole(SystemRole user, String operatorID) {
        // 创建角色
        BaseDataUtil.setBaseDataForEntity(user,"1",operatorID);
        systemRoleMapper.insertSelective(user);
        return true;
    }

    /**
     * 更新实体
     */
    @Transactional
    public boolean modifySystemRole(SystemRole user, String operatorID) {
        // 更新角色
        BaseDataUtil.setBaseDataForEntity(user,"2",operatorID);
        systemRoleMapper.updateByPrimaryKeySelective(user);
        return true;
    }

    /**
     * 删除实体
     */
    @Transactional
    public boolean removeSystemRole(SystemRole user, String operatorID) {
        // 删除角色
        BaseDataUtil.setBaseDataForEntity(user,"3",operatorID);
        systemRoleMapper.updateByPrimaryKeySelective(user);
        return true;
    }
}
